$(function () {
    // 获取关注列表
    var loading = weui.loading('loading', {
        className: 'custom-classname'
    });
    var result = Model.user.getMyAttention({
        type: 0
    });
    if (!sessionStorage.getItem('hmdj_stopError')) {
        sessionStorage.setItem('hmdj_stopError', true);
    } else {
        if (result.code) {
            Common.fn.formatOutput(result);
            loading.hide();
            return false;
        }
    }
    for (var i = 0; i < result.data.length; i++) {
        var item = '<div class="weui-cell concerns-item" data-link="' + result.data[i].businessId + '"><div class="shop-vendor-left"><div class="portrait-block"><img class="portrait-img" src="' + result.data[i].photo + '"></div></div><div class="weui-cell__hd"><label class="vendor-level fans-grade">v' + result.data[i].grade + '</label></div><div class="weui-cell__bd"><h3 class="text-1-4">' + result.data[i].nickname + '</h3></div><div class="weui-cell__ft"><a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default cancel-concerns" data-id="' + result.data[i].businessId + '">已关注</a></div></div>';
        $(".list-concerns").append(item);
    }
    loading.hide();
});

$(document).on("mousedown", ".cancel-concerns", function (event) {
    var id = $(this).attr("data-id"),
        result = '';
    var confirms = weui.confirm(
        "真的要取消关注吗？",
        function () {
            // 取消关注
            result = Model.business.attendBusiness({
                businessId: id
            });
            if (result.code) {
                alert(result.message);
                location.reload();
                return false;
            }
            location.reload();
        },
        function () {
        }
    );
});

$(document).on("click", ".concerns-item", function () {
    var id = $(this).attr("data-link");
    location.href = "shop_detail.html?id=" + id;
});